<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/1/17
  Time: 19:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form action="/stusys/registerServlet" method="get">
        <a href="login.jsp">返回登陆界面</a>
        ${requestScope.state}<br/>
        账号:<input type="text" name="username" id="username"><span id="span1"></span><br/>
        密码:<input type="password" name="password"><br/>
        确认密码:<input type="password" name="password1"><br/>
            <input type="submit" value="确认"><br/>
    </form>
    <script>
            //1.账号绑定失去焦点的事件
            document.getElementById("username").onblur=function () {
            //2.创建对象XMHttpRequest对象 用于和后台服务器进行交互
            let request = new XMLHttpRequest();
            //获取账号的值  getElementById:获取标签中元素的值
            let username = document.getElementById("username").value;
            //3.打开连接
            request.open("get","/stusys/validateServlet?username="+username,true)
            //4.发送请求
            request.send();
            //5.处理响应
            request.onreadystatechange=function () {
                if (request.readyState == 4 && request.status==200){
                    var responseText = request.responseText;
                    document.getElementById("span1").innerHTML=responseText;
                }
            }
        }
    </script>
</body>
</html>
